package com.git.hui.yinshua.biz.rest.app.index;

import com.git.hui.yinshua.api.model.ListRsp;
import com.git.hui.yinshua.api.model.ResVo;
import com.git.hui.yinshua.api.model.banner.BannerTabEnum;
import com.git.hui.yinshua.api.model.constants.GlobalConstants;
import com.git.hui.yinshua.biz.banner.service.BannerService;
import com.git.hui.yinshua.biz.goods.service.CategoryService;
import com.git.hui.yinshua.biz.goods.service.GoodsService;
import com.git.hui.yinshua.biz.rest.models.banner.res.BannerDto;
import com.git.hui.yinshua.biz.rest.models.goods.req.GoodsQueryReq;
import com.git.hui.yinshua.biz.rest.models.goods.rsp.CategoryDto;
import com.git.hui.yinshua.biz.rest.models.goods.rsp.GoodsInfoDto;
import com.git.hui.yinshua.biz.rest.models.index.AppIndexRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author YiHui
 * @date 2024/6/18
 */
@RestController
@RequestMapping(path = "app")
public class AppIndexController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private BannerService bannerService;

    /**
     * 商品列表
     *
     * @return
     */
    @GetMapping("list")
    public ResVo<AppIndexRes> index(GoodsQueryReq req) {
        req.setState(GlobalConstants.GoodsApi.GOODS_ONLINE_STATE);
        ListRsp<GoodsInfoDto> goodsWall = goodsService.queryGoodsWall(req);
        List<GoodsInfoDto> recommends = goodsService.queryRecommendList();
        List<BannerDto> banners = bannerService.queryForTab(BannerTabEnum.HOME);

        AppIndexRes res = new AppIndexRes();
        res.setBannerList(banners);
        res.setGoodsList(goodsWall);
        res.setRecommendGoods(recommends);
        return ResVo.ok(res);
    }

    /**
     * 翻页,加载更多
     *
     * @param req
     * @return
     */
    @GetMapping("next")
    public ResVo<ListRsp<GoodsInfoDto>> more(GoodsQueryReq req) {
        req.setState(GlobalConstants.GoodsApi.GOODS_ONLINE_STATE);
        ListRsp<GoodsInfoDto> goodsWall = goodsService.queryGoodsWall(req);
        return ResVo.ok(goodsWall);
    }

    /**
     * 商品类目
     *
     * @return
     */
    @GetMapping("categoryList")
    public ResVo<List<CategoryDto>> categoryList() {
        List<CategoryDto> list = categoryService.listTotalEffectCategory();
        return ResVo.ok(list);
    }

    /**
     * 分类商品列表
     *
     * @param req
     * @return
     */
    @GetMapping("categoryGoodsList")
    public ResVo<ListRsp<GoodsInfoDto>> categoryGoods(GoodsQueryReq req) {
        ListRsp<GoodsInfoDto> list = goodsService.queryCategoryGoods(req);
        return ResVo.ok(list);
    }

    /**
     * 客服列表
     *
     * @return
     */
    @GetMapping("customer")
    public ResVo<List<BannerDto>> customList() {
        List<BannerDto> list = bannerService.queryForTab(BannerTabEnum.CUSTOMER_SERVICE);
        return ResVo.ok(list);
    }
}
